#!/bin/bash

path=$(cd `dirname $0`/../; pwd)

docker compose -f docker-compose-dev.yml down

if [[ "$1" == "build" ]]; then
  cd ${path}/scaffold-website
  npm run build

  cd ${path}
  mvn clean package -DskipTests=true
fi

if [[ -f "${path}/scaffold-web/target/service.tar.gz" ]]; then
  cp -f ${path}/scaffold-web/target/service.tar.gz ${path}/docker
fi

if [[ -d "${path}/scaffold-website/dist" ]]; then
  rm -rf ${path}/docker/dist
  cp -rf ${path}/scaffold-website/dist ${path}/docker
fi

cd ${path}/docker
docker build -f ./Dockerfile-server -t scaffold-server:latest .
docker build -f ./Dockerfile-web -t scaffold-web:latest .

rm -rf dist
rm -rf service.tar.gz

docker compose -f docker-compose-dev.yml up -d